package com.mdx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mdx.bean.ClassBean;
import com.mdx.service.IClassService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 小班
 */
@RestController
@RequestMapping("class")
public class ClassController {
    @Resource
    private IClassService classService;

    //查询所有班级
    @RequestMapping("findAll")
    public IPage<ClassBean> findAll(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                    @RequestParam(value = "pageSize", defaultValue = "2") int pageSize){
        return classService.showClassByItem(pageNO,pageSize,null,null);
    }

    //修改班级
    @RequestMapping("update")
    public String update(int classId,String head,String headTel){
        classService.updateHeadAndTel(classId,head,headTel);
        return "ok";
    }

    //添加
    @RequestMapping("add")
    public String add(ClassBean classBean){
        classService.addClass(classBean);
        return "ok";
    }

    //根据id查询班级详情
    @RequestMapping("findById")
    public ClassBean findById(int classId){
        return classService.getById(classId);
    }

    //模糊查询
    @RequestMapping("findByItem")
    public IPage<ClassBean> findByItem(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                    @RequestParam(value = "pageSize", defaultValue = "2") int pageSize,
                                       String className,String regionName){
        return classService.showClassByItem(pageNO,pageSize,className,regionName);
    }
}
